package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class JspEnvInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            PrintWriter out = response.getWriter();
            out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">" +
                    "      <tr>" +
                    "        <td><h2 id=\"Ninty_H2_Title\">System Properties &gt;&gt;</h2>" +
                    "          <div id=\"ghaB\">" +
                    "            <hr style=\" border: 1px solid #ddd;height:0px;\"/>" +
                    "            <ul id=\"Ninty_Ul_Sys\" class=\"info\">");
            Properties pro = System.getProperties();
            Enumeration names = pro.propertyNames();
            while (names.hasMoreElements()) {
                String name = (String) names.nextElement();
                out.println("<li><u>" + Utils.htmlEncode(name) + " : </u>" + Utils.htmlEncode(pro.getProperty(name)) + "</li>");
            }
            out.println("</ul><h2 id=\"Ninty_H2_Mac\">System Environment &gt;&gt;</h2><hr style=\" border: 1px solid #ddd;height:0px;\"/><ul id=\"Ninty_Ul_Sys\" class=\"info\">");
            Map<String, String> envs = System.getenv();
            Set<Map.Entry<String, String>> entrySet = envs.entrySet();
            for (Map.Entry<String, String> en : entrySet) {
                out.println("<li><u>" + Utils.htmlEncode(en.getKey()) + " : </u>" + Utils.htmlEncode(en.getValue()) + "</li>");
            }
            out.println("</ul></div></td>" +
                    "      </tr>" +
                    "    </table>");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}